//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.goldhuman.IO.Protocol;

import com.goldhuman.Common.Octets;

import java.net.SocketAddress;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public abstract class Manager {
    private Set<com.goldhuman.IO.Protocol.Session> set = Collections.synchronizedSet(new HashSet());

    protected void AddSession(com.goldhuman.IO.Protocol.Session session) {
        this.set.add(session);

        try {
            this.OnAddSession(session);
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }

    protected void DelSession(com.goldhuman.IO.Protocol.Session session) {
        try {
            this.OnDelSession(session);
        } catch (Exception var3) {
            var3.printStackTrace();
        }

        this.set.remove(session);
    }

    protected void AbortSession(com.goldhuman.IO.Protocol.Session session) {
        try {
            this.OnAbortSession(session);
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }

    public boolean SetISecurity(com.goldhuman.IO.Protocol.Session session, String type, Octets key) {
        if (!this.set.contains(session)) {
            return false;
        } else {
            session.SetISecurity(type, key);
            return true;
        }
    }

    public boolean SetOSecurity(com.goldhuman.IO.Protocol.Session session, String type, Octets key) {
        if (!this.set.contains(session)) {
            return false;
        } else {
            session.SetOSecurity(type, key);
            return true;
        }
    }

    public boolean Send(com.goldhuman.IO.Protocol.Session session, Protocol protocol) {
        return !this.set.contains(session) ? false : session.Send(protocol);
    }

    public boolean Close(com.goldhuman.IO.Protocol.Session session) {
        if (!this.set.contains(session)) {
            return false;
        } else {
            session.Close();
            return true;
        }
    }

    public boolean ChangeState(com.goldhuman.IO.Protocol.Session session, String name) {
        if (!this.set.contains(session)) {
            return false;
        } else {
            session.ChangeState(name);
            return true;
        }
    }

    protected abstract void OnAddSession(com.goldhuman.IO.Protocol.Session var1);

    protected abstract void OnDelSession(com.goldhuman.IO.Protocol.Session var1);

    protected void OnAbortSession(Session session) {
    }

    protected abstract State GetInitState();

    protected int PriorPolicy(int type) {
        return Protocol.GetStub(type).PriorPolicy();
    }

    protected boolean InputPolicy(int type, int size) {
        return Protocol.GetStub(type).SizePolicy(size);
    }

    protected abstract String Identification();

    protected SocketAddress OnCheckAddress(SocketAddress sa) {
        return sa;
    }

    protected Manager() {
    }
}
